# tools/pdf_tools.py
import os
import sys
from typing import Optional

# Add parent dir
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(parent_dir)
from mcp_utils import safe_tool


@safe_tool
def list_files(directory: str = ".") -> dict:
    """列出指定目录下的文件与文件夹"""
    if not os.path.exists(directory):
        raise FileNotFoundError(f"目录 '{directory}' 不存在。")
    items = os.listdir(directory)
    return {"path": os.path.abspath(directory), "items": items}


@safe_tool
def system_info() -> dict:
    """返回当前操作系统基本信息"""
    import platform, psutil
    return {
        "os": platform.system(),
        "version": platform.version(),
        "cpu_count": psutil.cpu_count(),
        "memory_GB": round(psutil.virtual_memory().total / 1e9, 2)
    }